import pandas as pd


def read_json():
    df = pd.read_json('abc.json')
    print(df.to_string())


def create_df():
    data =[
        {
            "id": "A001",
            "name": "菜鸟教程",
            "url": "www.runoob.com",
            "likes": 61
        },
        {
            "id": "A002",
            "name": "Google",
            "url": "www.google.com",
            "likes": 124
        },
        {
            "id": "A003",
            "name": "淘宝",
            "url": "www.taobao.com",
            "likes": 45
        }
    ]
    df = pd.DataFrame(data)
    print(df)

# 字典格式的 JSON
def dict_json():
    s = {
        "col1":{"row1":1,"row2":2,"row3":3},
        "col2":{"row1":"x","row2":"y","row3":"z"}
    }
    # 读取 JSON 转为 DataFrame
    df = pd.DataFrame(s)
    print(df)

# 从 URL 中读取 JSON 数据：
def read_url_json():
    url = 'https://static.runoob.com/download/sites.json'
    res = pd.read_json(url)
    print(res)

def read_local_json():
    df = pd.read_json('nested_list.json')
    print(df)

if __name__ == '__main__':
    # read_json()
    # create_df()
    # dict_json()
    # read_url_json()
    read_local_json()